package com.nanyang.tms.manager.storedrule.impl;

import com.nanyang.common.tool.utils.uuid.GlobalIdGeneratorUtil;
import com.nanyang.tms.common.contstant.TmsSerializeConstant;
import com.nanyang.tms.common.exception.TmsManagerException;
import com.nanyang.tms.common.util.TmsExceptionUtil;
import com.nanyang.tms.dao.stored.StoredRuleDao;
import com.nanyang.tms.domain.stored.StoredRuleDO;
import com.nanyang.tms.manager.storedrule.StoredRuleManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component("storedRuleManager")
public class StoredRuleManagerImpl implements StoredRuleManager {
    @Autowired
    private StoredRuleDao storedRuleDao;
    @Autowired
    private GlobalIdGeneratorUtil globalIdGeneratorUtil;

    @Override
    public void saveStoredRule(StoredRuleDO storedRuleDO) {
        try {
            storedRuleDO.setRuleCode(TmsSerializeConstant.STOREDRULR_KEY+globalIdGeneratorUtil.getNextSeq(TmsSerializeConstant.STOREDRULR_SEQ_KEY, TmsSerializeConstant.SEQ_INCRBY));
            storedRuleDao.insert(storedRuleDO);
        } catch (TmsManagerException e) {
            throw TmsExceptionUtil.wrapException(e);
        }
    }
}
